﻿using System.Collections.Generic;

namespace ProblemsSet
{
    public class Problem_135 : BaseProblem
    {
        public override object GetResult()
        {
            const int max = 1000000;

            var dct = new Dictionary<long, long>();

            for (long y = 2; y <= max; y++)
            {
                for (long d = y/4+1; d <= y-1; d++)
                {
                    long n = y*(4*d - y);
                    if (n <=0) continue;
                    if (n >= max)
                        break;
                    if (!dct.ContainsKey(n))
                        dct.Add(n, 0);
                    dct[n]++;
                }
            }
            long res = 0;
            foreach (var pair in dct)
            {
                if (pair.Value == 10)
                    res++;
            }
            return res;
        }

        public override string Problem
        {
            get
            {
                return @"Given the positive integers, x, y, and z, are consecutive terms of an arithmetic progression, the least value of the positive integer, n, for which the equation, x2  y2  z2 = n, has exactly two solutions is n = 27:

342  272  202 = 122  92  62 = 27

It turns out that n = 1155 is the least value which has exactly ten solutions.

How many values of n less than one million have exactly ten distinct solutions?";
            }
        }

        public override bool IsSolved
        {
            get
            {
                return true;
            }
        }

        public override object Answer
        {
            get
            {
                return 4989;
            }
        }
    }
}
